package com.eyllo.trackerdemo;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.widget.Toast;

public class TrackerViewActivity extends Activity {
	private static final String TAG = "CVCTracker::Activity";

	private MobileSensorFusion mMsf = null;
	
	private MenuItem mItemPreviewCanny;
	private MenuItem mItemPreviewNatural;
	private MenuItem mItemPreviewChessboard;
	private MenuItem mItemPreviewChessboardKlt;
	private MenuItem mItemPreviewNaturalKlt;
	private MenuItem mItemPreviewRestartKlt;
	private MenuItem mItemPreviewDetection;
	private Sample4View mView;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Log.i(TAG, "onCreate");
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		mMsf = new MobileSensorFusion(this);
		mView = new Sample4View(this);
		mView.mMsf = mMsf;
		setContentView(mView);
	}

	@Override
	protected void onPause() {
		super.onPause();
		mMsf.stop();
	}

	@Override
	protected void onResume() {
		super.onResume();
		mMsf.start();
	}

	public boolean onCreateOptionsMenu(Menu menu) {
		Log.i(TAG, "onCreateOptionsMenu");
		mItemPreviewCanny = menu.add("Canny");
		mItemPreviewDetection = menu.add("Detection");
		mItemPreviewNaturalKlt = menu.add("Natural with KLT");
		mItemPreviewRestartKlt = menu.add("Restart Klt");
		mItemPreviewNatural = menu.add("Natural");
		mItemPreviewChessboard = menu.add("Chessboard");
		mItemPreviewChessboardKlt = menu.add("Chessboard with KLT");
		
		return true;
	}

	public boolean onOptionsItemSelected(MenuItem item) {
		Log.i(TAG, "Menu Item selected " + item);
		if (item == mItemPreviewCanny) {
			mView.setViewMode( ViewMode.CANNY);
			showMode("Canny");
		} else if (item == mItemPreviewNatural) {
			mView.setViewMode( ViewMode.NATURAL);
			showMode("Natural");
		}else if (item == mItemPreviewChessboard) {
			mView.setViewMode( ViewMode.CHESS);
			showMode("Chess");
		}else if (item == mItemPreviewChessboardKlt) {
			mView.setViewMode( ViewMode.CHESS_KLT);
			showMode("Chess KLT");
		}else if (item == mItemPreviewNaturalKlt) {
			mView.setViewMode( ViewMode.NATURAL_KLT);
			showMode("Natural KLT");
		}else if (item == mItemPreviewRestartKlt) {
			mView.setViewMode( ViewMode.RESTART);
			showMode("Restart KLT");
		}else if (item == mItemPreviewDetection) {
			mView.setViewMode( ViewMode.DETECTION);
			showMode("Detection");
		}
		return true;
	}

	private void showMode(CharSequence text) {
		Context context = getApplicationContext();
		int duration = Toast.LENGTH_SHORT;
		Toast toast = Toast.makeText(context, text, duration);
		toast.show();
	}

}